<?php

use kartik\widgets\ActiveForm;
use kartik\widgets\FileInput;
use yii\helpers\Html;
use yii\widgets\Pjax;


$activity = $this->context->activity;
$this->title = $activity->title;


$regularLangName = \Yii::$app->czaHelper->getRegularLangName();
$messageName = $model->getMessageName();
?>

<style>

    .pr {
        position: relative;
    }

    .image_inp, .preview {
        height: 200px;
        /*line-height: 200px;*/
        /*background: url("/images/common/image_inp.png") no-repeat center;*/
        background-color: #eeeeee;
        text-align: center;
    }

    .mt10 {
        margin-top: 10px;
    }

    .image_inp input {
        position: absolute;
        right: 0;
        top: 10px;
        height: 200px;
        width: 100%;
        opacity: 0;
        filter: alpha(opacity=0);
        cursor: pointer
    }

    .image_text {
        font-size: 18px;
        font-weight: bold;
        color: gray;
    }


</style>

<?php
\yii\bootstrap\Modal::begin([
    'id' => 'content-modal',
    'header' => '<p class="modal-title"></p>',
]);
\yii\bootstrap\Modal::end();

?>

<?= \frontend\widgets\Swiper::widget(['model' => $activity]) ?>

<?php Pjax::begin(['id' => $model->getDetailPjaxName(), 'formSelector' => $model->getBaseFormName(true), 'enablePushState' => false, 'clientOptions' => [
    'skipOuterContainers' => true
]]) ?>

<?php
$form = ActiveForm::begin([
    'action' => ['index', 'c' => $activity->seo_code],
    'options' => [
        'id' => $model->getBaseFormName(),
        'data-pjax' => true,
    ]]);
?>


<?php if (Yii::$app->session->hasFlash($messageName)): ?>
    <?php
    $js = "$('#content-modal').find('.modal-title').html('提示');
     $('#content-modal').modal('show').find('.modal-body').html('" . Yii::$app->session->getFlash($messageName)[0] . "');";
    $this->registerJs($js);
    ?>
<?php endif; ?>


<div class="container-fluid <?= $model->getPrefixName('form') ?>">
    <div class="r4_card pr">

        <p class="main-font-color p_title"><?= Yii::t('app.c2', 'Edit Information') ?></p>

        <!--        <div class="image_inp">-->
        <!--            <div class="image_content">-->
        <!--                <img id="preview" src="/images/common/image_inp.png">-->
        <!--            </div>-->
        <!--            --><?php //echo $form->field($model, 'avatar')->fileInput(['id' => 'img_inp'])
        //                 ->label(false) ?>
        <!--            <p class="image_text">点击上传头像</p>-->
        <!--        </div>-->

        <?php

        // A block file picker button with custom icon and label
        echo FileInput::widget([
            'name' => 'avatar',
            'pluginOptions' => [
                'showCaption' => false,
                'showRemove' => false,
                'showUpload' => false,
                'browseClass' => 'btn main-bg-color btn-block white-font',
                'browseIcon' => '<i class="glyphicon glyphicon-camera"></i> ',
                'browseLabel' => Yii::t('app.c2', 'Select Photo')
            ],
            'options' => ['accept' => 'image/*']
        ]);
        ?>

        <div class="input-group mt10">
            <span class="input-group-addon" id="sizing-addon2"><?= Yii::t('app.c2', 'Player Name') ?></span>
            <?=
            $form->field($model, 'label', ['errorOptions' => ['tag' => false]])
                ->textInput()
                ->label(false)
            ?>
        </div>

        <div class="input-group mt10">
            <span class="input-group-addon" id="sizing-addon2"><?= Yii::t('app.c2', 'Mobile Number') ?></span>
            <?=
            $form->field($model, 'mobile_number', ['errorOptions' => ['tag' => false]])
                ->textInput()
                ->label(false)
            ?>
        </div>

        <p class="main-font-color p_title"><?= Yii::t('app.c2', 'Detail Introduction') ?></p>

        <?php

        echo $form->field($model, 'content')->textArea([
            'rows' => 4
        ])->label(false)

        ?>

        <p class="main-font-color p_title"><?= Yii::t('app.c2', 'Activity Introduction') ?></p>

        <div class="r4_card content">
            <?= $activity->content ?>
        </div>

        <div class="form-group">
            <?= Html::submitButton(Yii::t('app.c2', 'Submit Apply'), ['class' => 'btn main-bg-color white-font btn-block',
                'name' => 'login-button']) ?>
        </div>

    </div>
</div>

<?php ActiveForm::end(); ?>

<?php Pjax::end() ?>
<?php
$js = <<<JS

$("#img_inp").on("change", function(e){
    
  var file = e.target.files[0]; //获取图片资源

  // 只选择图片文件
  if (!file.type.match('image.*')) {
    return false;
  }

  var reader = new FileReader();

  reader.readAsDataURL(file); // 读取文件

  // 渲染文件
  reader.onload = function(arg) {

    var img = '<img class="preview" src="' + arg.target.result + '" alt="preview"/>';
    $(".image_content").empty().append(img);
    $(".image_text").hide();
  }
});


JS;

// $this->registerJs($js);


?>


<script type="text/javascript">
    wx.ready(function () {   //需在用户可能点击分享按钮前就先调用
        //shareData 参数记得为字符串类型
        var shareData = {
            title: '<?= $activity->title ?>',
            desc: '<?= Html::encode($activity->content) ?>',//这里请特别注意是要去除html
            link: '<?= Yii::$app->request->hostInfo . Yii::$app->request->url ?>',//域名必须JS安全域名
            imgUrl: '<?= $activity->getThumbnailUrl() ?>',
            success: function () {

            },
            cancel: function () {
                console.log('cancel')
            }
        };

        if (wx.onMenuShareAppMessage) { //微信文档中提到这两个接口即将弃用，故判断
            wx.onMenuShareAppMessage(shareData);//1.0 分享到朋友
            wx.onMenuShareTimeline(shareData);//1.0分享到朋友圈
        } else {
            wx.updateAppMessageShareData(shareData);//1.4 分享到朋友
            wx.updateTimelineShareData(shareData);//1.4分享到朋友圈
        }

    });
</script>
